// ----------------------------------------------------------------------------
// Copyright 2006, Martin D. Flynn
// All rights reserved
// ----------------------------------------------------------------------------
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Description:
//  This class is a container for GPS based event modules.  During initialization
//  modules witl be added to this class via 'addModule', and will later be
//  invoked periodically via 'checkGPS'.
// ----------------------------------------------------------------------------
// Change History:
//  2006/03/26  Martin D. Flynn
//      Initial release
// ----------------------------------------------------------------------------
package org.opendmtp.j2me.client.base;

import java.util.Enumeration;
import java.util.Vector;

import org.opendmtp.j2me.util.GeoEvent;

/**
 * Implements modules for the handling of GPS event data.
 * 
 * @author Martin D. Flynn, Joshua Stupplebeen
 */
public class GPSModules {

  // ------------------------------------------------------------------------

  private Vector gpsModules = null;

  /**
   * GPSModules constructor instantiating a new empty vector list.
   */
  public GPSModules() {
    this.gpsModules = new Vector();
  }

  // ------------------------------------------------------------------------

  /**
   * Adds a module to the Vector list of modules.
   * 
   * @param mod GPSModule.Module new gps module
   */
  public void addModule(GPSModules.Module mod) {
    
    if ((mod != null) && !this.gpsModules.contains(mod)) {
      this.gpsModules.addElement(mod);
    }
  }

  // ------------------------------------------------------------------------

  /**
   * Iterates through the Vector list recursively calling checkGPS. 
   * I'm not sure what this method's intention is, but i'm assuming 
   * its checking whether the GPSModules contained in the Vector list
   * have both GPS coordinates.
   * 
   * @param oldFix old gps event.
   * @param newFix new gps event.
   */
  public void checkGPS(GeoEvent oldFix, GeoEvent newFix) {
    
    for (Enumeration i = this.gpsModules.elements(); i.hasMoreElements();) {
      GPSModules.Module m = (GPSModules.Module) i.nextElement();
      m.checkGPS(oldFix, newFix);
    }
  }

  // ------------------------------------------------------------------------

  /**
   * Module interface implemented with 2 GPS data points.
   */
  public interface Module {
    
    /**
     * Checks the gps event checking modules.
     * 
     * @param oldFix old gps event.
     * @param newFix new gps event.
     */
    public void checkGPS(GeoEvent oldFix, GeoEvent newFix);
  }

}
